import { apiSlice } from "@store/apiSlice/index";

export const patientApiSlice = apiSlice
  .enhanceEndpoints({ addTagTypes: ["patients"] })
  .injectEndpoints({
    endpoints: (builder) => ({
      // 查询患者列表
      requestPatients: builder.query<PatientResponse, undefined>({
        query: () => ({ url: "/patient/mylist" }),
        providesTags: ["patients"],
      }),
      // 添加患者
      addPatient: builder.mutation<
        HealthResponse<{ id: string }>,
        Pick<Patient, "name" | "idCard" | "defaultFlag" | "gender">
      >({
        query: (body) => ({ url: "/patient/add", method: "POST", body }),
        invalidatesTags: ["patients"],
      }),
      // 删除患者
    removePatient: builder.mutation<HealthResponse<{ id: string }>, string>({
      query: (id) => ({ url: `/patient/del/${id}`, method: "DELETE" }),
      invalidatesTags: ["patients"],
    }),
    
    }),
  });

export const { useRequestPatientsQuery,useAddPatientMutation,useRemovePatientMutation } = patientApiSlice;